<?php
/**
 * class FavoritesAdderModel
 */
class FavoritesAdderModel extends Model{

    function __construct() {
        parent::__construct();
    }
    
    public function saveFavorite($data) {
        if ($this->db->query("INSERT INTO favorites (user_id, page)
                                 VALUES ('" . intval($data['user_id']) . "',
                                         '" . htmlspecialchars(str_replace('/', '_', $data['page'])) . "')"))
            return mysql_insert_id();
        else
            return false;
    }

    public function isAlreadyAdded($page, $user_id) {
        $total = $this->db->query("SELECT COUNT(*) AS num FROM favorites WHERE page = '" . htmlspecialchars(str_replace('/', '_', $page)) . "' AND user_id = '".  intval($user_id)."'");
        return (boolean)$total->row['num'][0];
    }

}




?>